using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
using Web.Core;

namespace AsmxData
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class OrdersHandler : System.Web.Services.WebService
    {
        /// 
        [WebMethod]
        public string getList(string injson)
        {
		    JsonFormat jsf = new JsonFormat(injson);
		    if (!Authority.CheckAuthOnAsmx("OrdersHandler.getList",jsf.GetValue("authid"), jsf.GetValue("authstr"), true))
			  return "{\"result\":\"-1\"}";
            int pagesize = Int16.Parse(jsf.GetValue("rows"));
            int currentpage = Int16.Parse(jsf.GetValue("page"));
            PageInfo pi = new PageInfo();
            pi.PageSize = pagesize;
            pi.PageIndex = currentpage;
    		Model.Orders mdl = new Model.Orders();
        
            PageList<Model.Orders> lst = new BLL.Orders().GetPageList(pi, mdl);
            string json = "{\"total\":" + pi.RecordCount.ToString()+",\"rows";
            json = Newtonsoft.Json.JavaScriptConvert.SerializeObject(lst).Replace("{\"List", json);
			return json;
        }

        /// 
        [WebMethod]
        public string getOne(string injson)
        {
		    JsonFormat jsf = new JsonFormat(injson);
		    if (!Authority.CheckAuthOnAsmx("OrdersHandler.getOne",jsf.GetValue("authid"), jsf.GetValue("authstr"), true))
			  return "{\"result\":\"-1\"}";
            int? id = BLL.BLHelper.GetInt(jsf.GetValue("id"));
	    	Model.Orders wheremdl = new Model.Orders();
    		wheremdl.OrderId = id;
            Model.Orders mdl = new BLL.Orders().GetModel(wheremdl);
            string json = "\"result\":{0},\"model\":{1}";
            if (mdl == null)
                json = String.Format(json, 0, "{}");
            else
                json = String.Format(json, 1, Newtonsoft.Json.JavaScriptConvert.SerializeObject(mdl));
            return "{" + json + "}";
        }

        /// 
        [WebMethod]
        public string AddOne(string injson)
        {
		    JsonFormat jsf = new JsonFormat(injson);
		    if (!Authority.CheckAuthOnAsmx("OrdersHandler.AddOne",jsf.GetValue("authid"), jsf.GetValue("authstr"), true))
			  return "{\"result\":\"-1\"}";
            Model.Orders mdl = new Model.Orders();
	
            mdl.OrderNumber = BLL.BLHelper.GetString(jsf.GetValue("OrderNumber"));
            mdl.UserId = BLL.BLHelper.GetInt(jsf.GetValue("UserId"));
            mdl.UserName = BLL.BLHelper.GetString(jsf.GetValue("UserName"));
            mdl.TotalMoney = BLL.BLHelper.GetDecimal(jsf.GetValue("TotalMoney"));
            mdl.Alipay = BLL.BLHelper.GetString(jsf.GetValue("Alipay"));
            mdl.TenPay = BLL.BLHelper.GetString(jsf.GetValue("TenPay"));
            mdl.Tel = BLL.BLHelper.GetString(jsf.GetValue("Tel"));
            mdl.Adderss = BLL.BLHelper.GetString(jsf.GetValue("Adderss"));
            mdl.RealName = BLL.BLHelper.GetString(jsf.GetValue("RealName"));
            mdl.IsPay = BLL.BLHelper.GetBool(jsf.GetValue("IsPay"));
            mdl.IsSend = BLL.BLHelper.GetBool(jsf.GetValue("IsSend"));
            mdl.IsCofim = BLL.BLHelper.GetBool(jsf.GetValue("IsCofim"));
            mdl.IsCancel = BLL.BLHelper.GetBool(jsf.GetValue("IsCancel"));
            mdl.PayTime = BLL.BLHelper.GetDateTime(jsf.GetValue("PayTime"));
            mdl.CofimTime = BLL.BLHelper.GetDateTime(jsf.GetValue("CofimTime"));
            mdl.SendTime = BLL.BLHelper.GetDateTime(jsf.GetValue("SendTime"));
            mdl.CancelTime = BLL.BLHelper.GetDateTime(jsf.GetValue("CancelTime"));
            mdl.CofimUser = BLL.BLHelper.GetString(jsf.GetValue("CofimUser"));
            mdl.SendUser = BLL.BLHelper.GetString(jsf.GetValue("SendUser"));
            mdl.CancelUser = BLL.BLHelper.GetString(jsf.GetValue("CancelUser"));
            mdl.CofimComment = BLL.BLHelper.GetString(jsf.GetValue("CofimComment"));
            mdl.SendComment = BLL.BLHelper.GetString(jsf.GetValue("SendComment"));
            mdl.CancelComment = BLL.BLHelper.GetString(jsf.GetValue("CancelComment"));
            new BLL.Orders().Add(mdl);
            return "{\"result\":\"1\"}";
        }

        /// 
        [WebMethod]
        public string RemoveOne(string injson)
        {
		    JsonFormat jsf = new JsonFormat(injson);
		    if (!Authority.CheckAuthOnAsmx("OrdersHandler.RemoveOne",jsf.GetValue("authid"), jsf.GetValue("authstr"), true))
			  return "{\"result\":\"-1\"}";
            int? id = BLL.BLHelper.GetInt(jsf.GetValue("id"));
            Model.Orders wheremdl = new Model.Orders();
	    	wheremdl.OrderId = id;
	    	new BLL.Orders().Delete(wheremdl);
	    	return "{\"result\":\"1\"}";
        }

        /// 
        [WebMethod]
        public string UpdataOne(string injson)
        {
		    JsonFormat jsf = new JsonFormat(injson);
		    if (!Authority.CheckAuthOnAsmx("OrdersHandler.UpdataOne",jsf.GetValue("authid"), jsf.GetValue("authstr"), true))
			  return "{\"result\":\"-1\"}";
            Model.Orders setmdl = new Model.Orders();
	    	Model.Orders wheremdl = new Model.Orders();
	
            setmdl.OrderId = BLL.BLHelper.GetInt(jsf.GetValue("OrderId"));
            setmdl.OrderNumber = BLL.BLHelper.GetString(jsf.GetValue("OrderNumber"));
            setmdl.UserId = BLL.BLHelper.GetInt(jsf.GetValue("UserId"));
            setmdl.UserName = BLL.BLHelper.GetString(jsf.GetValue("UserName"));
            setmdl.TotalMoney = BLL.BLHelper.GetDecimal(jsf.GetValue("TotalMoney"));
            setmdl.Alipay = BLL.BLHelper.GetString(jsf.GetValue("Alipay"));
            setmdl.TenPay = BLL.BLHelper.GetString(jsf.GetValue("TenPay"));
            setmdl.Tel = BLL.BLHelper.GetString(jsf.GetValue("Tel"));
            setmdl.Adderss = BLL.BLHelper.GetString(jsf.GetValue("Adderss"));
            setmdl.RealName = BLL.BLHelper.GetString(jsf.GetValue("RealName"));
            setmdl.IsPay = BLL.BLHelper.GetBool(jsf.GetValue("IsPay"));
            setmdl.IsSend = BLL.BLHelper.GetBool(jsf.GetValue("IsSend"));
            setmdl.IsCofim = BLL.BLHelper.GetBool(jsf.GetValue("IsCofim"));
            setmdl.IsCancel = BLL.BLHelper.GetBool(jsf.GetValue("IsCancel"));
            setmdl.PayTime = BLL.BLHelper.GetDateTime(jsf.GetValue("PayTime"));
            setmdl.CofimTime = BLL.BLHelper.GetDateTime(jsf.GetValue("CofimTime"));
            setmdl.SendTime = BLL.BLHelper.GetDateTime(jsf.GetValue("SendTime"));
            setmdl.CancelTime = BLL.BLHelper.GetDateTime(jsf.GetValue("CancelTime"));
            setmdl.CofimUser = BLL.BLHelper.GetString(jsf.GetValue("CofimUser"));
            setmdl.SendUser = BLL.BLHelper.GetString(jsf.GetValue("SendUser"));
            setmdl.CancelUser = BLL.BLHelper.GetString(jsf.GetValue("CancelUser"));
            setmdl.CofimComment = BLL.BLHelper.GetString(jsf.GetValue("CofimComment"));
            setmdl.SendComment = BLL.BLHelper.GetString(jsf.GetValue("SendComment"));
            setmdl.CancelComment = BLL.BLHelper.GetString(jsf.GetValue("CancelComment"));

            new BLL.Orders().Update(setmdl, wheremdl);
            return "{\"result\":\"1\"}";
        }
    }
}
  